﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage2.master" AutoEventWireup="true" CodeFile="Admin_XemChiTietDonHang.aspx.cs" Inherits="ChucNang_Admin_Admin_XemChiTietDonHang" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<%
    int id = int.Parse(Request.QueryString.Get("Id"));
    DataDSTableAdapters.DATHANGTableAdapter dhadapter = new DataDSTableAdapters.DATHANGTableAdapter();
    DataDS.DATHANGDataTable dhtable= dhadapter.DATHANG_LayDonHangTheoIdDonHang(id);
    Response.Write("<center>");
    Response.Write("Thời điểm đặt hàng:" + ((DateTime)dhtable.Rows[0]["ThoiGianDatHang"]).ToString("dd/M/yyyy HH:MM:s") + "<br />");
    int trangthai = int.Parse(dhtable.Rows[0]["TrangThai"].ToString());
    if (trangthai == 1)
    {
        object thoidiemhuy = dhtable.Rows[0]["ThoiGianHuy"];
        Response.Write("Thời điểm hủy:" + ((DateTime)thoidiemhuy).ToString("dd/M/yyyy HH:MM:s")+"<br />");
    }
    if (trangthai == 2)
    {
        Response.Write("Đang chờ giao <br/>");
    }
    if (trangthai == 3)
    {
        object thoidiemgiaohang = dhtable.Rows[0]["NgayDaGiaoHang"];
        Response.Write("Thời điểm giao hàng:" + ((DateTime)thoidiemgiaohang).ToString("dd/M/yyyy HH:MM:s") + "<br />");
        object idnhanvien = dhtable.Rows[0]["Id_NhanVienGiaoHang"];
        if (idnhanvien.ToString() != "")
        {
            DataDSTableAdapters.NHANVIENTableAdapter nvadapter = new DataDSTableAdapters.NHANVIENTableAdapter();
            DataDS.NHANVIENDataTable nvtable = nvadapter.NHANVIEN_LayTheoId((int)idnhanvien);
            Response.Write("Tên nhân viên giao hàng:" + nvtable.Rows[0]["TenNhanVien"].ToString()+"<br />");
        }
    }
    Response.Write("Tổng tiền:" + dhtable.Rows[0]["TongTien"].ToString() + "<br />");
    DataDSTableAdapters.CHITIETDONHANG_SANPHAMTableAdapter ctdhspadapter = new DataDSTableAdapters.CHITIETDONHANG_SANPHAMTableAdapter();
    DataDS.CHITIETDONHANG_SANPHAMDataTable ctdhsptable= ctdhspadapter.CHITIETDONHANG_SANPHAM_LayTheoIdDonHang(id);
    Response.Write("<b>Danh sách các sản phẩm</b>");
    Response.Write("<table>");
    Response.Write("<tr class='rowheader'>");
    Response.Write("<th>Hình ảnh</th>");
    Response.Write("<th>Tên sản phẩm</th>");
    Response.Write("<th>Giá 1 sản phẩm</th>");
    Response.Write("<th>Số lượng</th>");
    Response.Write("<th>Giá giảm</th>");
    Response.Write("<th>Sản phẩm khuyến mãi</th>");
    Response.Write("<th>Thành tiền</th>");
    Response.Write("</tr>");
    for (int i = 0; i < ctdhsptable.Rows.Count; i++)
    {
        string hinhanh = ctdhsptable.Rows[i]["HinhAnh"].ToString();
        hinhanh=hinhanh.Replace("~", "/SMO");
        string tensanpham = ctdhsptable.Rows[i]["TenSP"].ToString();
        string giasanpham = ctdhsptable.Rows[i]["DonGia"].ToString();
        string soluong = ctdhsptable.Rows[i]["SoLuong"].ToString();
        string tongtien = ctdhsptable.Rows[i]["TongTien"].ToString();
        float giamgia =100-( float.Parse(tongtien) * 100 / (float.Parse(giasanpham) * float.Parse(soluong)));
        Boolean khuyenmai = (Boolean)ctdhsptable.Rows[i]["Is_KhuyenMai"];
        if(i%2==0)
            Response.Write("<tr class='rowchan'>");
        else
            Response.Write("<tr class='rowle'>");
        Response.Write("<td><img width='50' height='50' src='" + hinhanh+"' /></td>");
        Response.Write("<td>"+ tensanpham+"</td>");
        Response.Write("<td>" + giasanpham + "</td>");
        Response.Write("<td>" + soluong + "</td>");
        Response.Write("<td>" + giamgia.ToString()+ " %</td>");
        if (khuyenmai == true)
        {
            Response.Write("<td>Sản phẩm khuyến mãi</td>");
        }
        else
        {
            Response.Write("<td></td>");
        }
        Response.Write("<td>" + tongtien+ "</td>");
        Response.Write("</tr>");
    }
    Response.Write("</table>");     

    Response.Write("</center>");
     %>
      <center>
          <asp:Button ID="btnBack" runat="server" Text="Trở Lại" onclick="btnBack_Click" 
            /></center>
</asp:Content>

